home *** CD-ROM | disk | FTP | other *** search
- Path: alterdial.uu.net!not-for-mail
- From: Chris Gould <cgould@dataware.com>
- Newsgroups: comp.lang.c++
- Subject: Re: [Q] Pointers to multi-D arrays
- Date: Fri, 12 Jan 1996 13:28:24 -0500
- Organization: Dataware Technologies, Inc.
- Message-ID: <30F6A848.602A@dataware.com>
- References: <4d4alj$5o8@news.cs.hope.edu>
- NNTP-Posting-Host: gw.dataware.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b3 (WinNT; I)
-
- Michael Van Opstall wrote:
- >
- > How do you make a pointer to a multi dimensional array?
- >
- > I have this:
- >
- > Complex* data;
- > // in the header
- > ...
- > // the constructor...
- > data=new Complex[v][h];
- >
- > and I get an error because it's trying to make an array of pointers to
- > arrays of Complex instead of one pointer to a larger array.
- >
-
- If you want a dynamic pointer to a 2x array you need to use a
- pointer to pointer.
-
- //header
- ...
- Complex **data;
- ...
-
- //constructor
- ...
- // allocate memory for the 2x array
- data = new Complex *[v];
- for ( i = 0; i < v; i++ ) {
- data[i] = new Complex[h];
- }
- ...
-